package com.hsource.doctorcenter.util;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.*;

/**
 * @author yangYang
 * @version 1.0
 * @date 2020/9/28 11:13
 * @describe 获取yml属性统一类
 */
@Component
public class StaticValue {

    /** 价格浮动比例 **/
    public static String PRICE_RATIO;

    /** 二甲医生 **/
    public static final String PAYTYPE_SECOND="qc_hospital_common";

    /** 三甲医生 **/
    public static final String PAYTYPE_THREE="qc_hospital_upgrade";

    public static String PARTNER_KEY;

    /** 文件上传路径 **/
    public static String UPLOAD_FILEURL;

    /** 系统指派医生价格 **/
    public static String SYSTEM_ASSIGNMENT_DOCTOR_PRICE;

    /** 支付中心接口 **/
    public static String PAYCENTER_API_URL;

    @Value("${chunyutianxia.partner_key}")
    public void setPARTNER_KEY(String PARTNER_KEY) {
        this.PARTNER_KEY = PARTNER_KEY;
    }

    @Value("${payCenter.api-url}")
    public void setPAYCENTER_API_URL(String PAYCENTER_API_URL) {
        this.PAYCENTER_API_URL = PAYCENTER_API_URL;
    }

    @Value("${doctorCenter.price-ratio}")
    public void setPRICE_RATIO(String PRICE_RATIO) {
        this.PRICE_RATIO = PRICE_RATIO;
    }

    @Value("${doctorCenter.upload-file}")
    public void setUPLOAD_FILEURL(String UPLOAD_FILEURL) {
        this.UPLOAD_FILEURL = UPLOAD_FILEURL;
    }

    @Value("${doctorCenter.system-assignment-doctor-price}")
    public void setSYSTEM_ASSIGNMENT_DOCTOR_PRICE(String SYSTEM_ASSIGNMENT_DOCTOR_PRICE) {
        this.SYSTEM_ASSIGNMENT_DOCTOR_PRICE = SYSTEM_ASSIGNMENT_DOCTOR_PRICE;
    }


    /**
     * 获取内容
     * @param images
     * @param contentString
     * @return
     */
    public static JSONArray getContent(List<String> images, String contentString){
        ArrayList<Map<String,String>> content_list = new ArrayList<>();
        if(StringUtils.isNotBlank(contentString)){
            Map<String,String> text = new HashMap<>();
            text.put("type", "text");
            text.put("text", contentString);
            content_list.add(text);
        }
        if(images.stream().count()>0){
            images.stream().forEach(s->{
                Map<String,String> image = new HashMap<>();
                image.put("type", "image");
                image.put("file", s);
                content_list.add(image);
            });
        }
       return JSONArray.parseArray(JSON.toJSONString(content_list));
    }

    /**
     * 获取内容
     * @param messageType
     * @param messageContent
     * @return
     */
    public static JSONArray getContent(String messageType,String messageContent){
        ArrayList<Map<String,String>> content_list = new ArrayList<>();
        if(messageType.equals("text")){
            Map<String,String> text = new HashMap<>();
            text.put("type", "text");
            text.put("text", messageContent);
            content_list.add(text);
        }
        if(messageType.equals("image")){
            Arrays.asList(messageContent.split(",")).stream().forEach(a->{
                Map<String,String> text = new HashMap<>();
                text.put("type", "image");
                text.put("file", a);
                content_list.add(text);
            });

        }
        if(messageType.equals("audio")){
            Arrays.asList(messageContent.split(",")).stream().forEach(a->{
                Map<String,String> text = new HashMap<>();
                text.put("type", "audio");
                text.put("file", a);
                content_list.add(text);
            });

        }
        return JSONArray.parseArray(JSON.toJSONString(content_list));
    }

}
